package ru;

import ru.algorithm.clusterization.cftree.CFTree;
import ru.algorithm.join.Distance;

import static ru.common.CommonUtils.iterable;

/**
 * Yuri Zemlyanskiy <urikz@yandex-team.ru>
 * Date: 04.05.2011
 */
public class Main {
    
    private static final int MAX_NODE_ENTRIES = 10;
    private static final double INITIAL_TRESHOLD = 0.5;
    private static final String TEST_DATA_PATH = "C:/!temp/test-data/10d-10c-no0.dat";
    private static final int DISTANCE_FUNCTION = CFTree.D0_DIST;
    private static final boolean APPLY_MERGING_REFINEMENT = false;

    public static void main(String[] args) throws Exception {

        CFTree birchTree =
                new CFTree(MAX_NODE_ENTRIES, INITIAL_TRESHOLD,
                        DISTANCE_FUNCTION, APPLY_MERGING_REFINEMENT);

        for (final double[] entry : iterable(new DoubleArrayReader(TEST_DATA_PATH))) {
            boolean inserted = birchTree.insertEntry(entry);
            if (!inserted) {
                System.err.println("ERROR: NOT INSERTED!");
                System.exit(1);
            }
        }

        birchTree.printLeafEntries();

    }

    static class EuclidDistance implements Distance<double[]> {

        public double dist(double[] t1, double[] t2) {
            double sum = 0.0;
            for (int i = 0; i < t1.length; i++) {
                sum += (t1[i] - t2[i])*(t1[i] - t2[i]);
            }
            return Math.sqrt(sum);
        }
    }

}
